<!doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  <title>我的</title>
  <link rel="stylesheet" type="text/css" href="../css/api.css" />
  <link rel="stylesheet" type="text/css" href="../css/my.css" />
</head>

<body>
  <div id="app" v-cloak>
    <div class="wrap flex-wrap flex-vertical">
      <div class="flex-con">
        <div class="user-info" @click="openEdit">
          <div class="avatar">
            <img id="avatar" :src="userInfo.avatar + '?imageView2/1/w/100/h/100'" alt="">
          </div>
          <div class="info">
            <div id="name" class="name">
              <span class="name-text">{{userInfo.name}}(ID{{userInfo.member_id}})</span>
              <span v-if="userInfo.level == '1'" class="icon icon-vip1"></span>
              <span v-if="userInfo.certification == '1'" class="icon icon-auth1"></span>
            </div>
            <div class="sign">{{userInfo.signature}}</div>
          </div>
        </div>
        <div class="menu-list">
          <div @click="openHistory" class="menu-item border-bottom">
            <i class="iconfont icon-zuji"></i>
            <div class="menu-info">
              <div class="title">我的访客</div>
            </div>
            <i class="iconfont icon-next"></i>
          </div>
        </div>
        <div class="menu-list">
          <div @click="openMyWallet" class="menu-item border-bottom">
            <i class="iconfont icon-wodeqianbao"></i>
            <div class="menu-info ">
              <div class="title">我的钱包</div>
            </div>
            <i class="iconfont icon-next"></i>
          </div>
          <div @click="openMyVip" class="menu-item border-bottom">
            <i class="iconfont icon-vip"></i>
            <div class="menu-info">
              <div class="title">我的VIP</div>
            </div>
            <i class="iconfont icon-next"></i>
          </div>
          <div @click="openMyShare" class="menu-item border-bottom">
            <i class="iconfont icon-shouyi"></i>
            <div class="menu-info">
              <div class="title">分成计划</div>
            </div>
            <i class="iconfont icon-next"></i>
          </div>
        </div>

        <div class="menu-list">
          <div @click="openOffer" class="menu-item border-bottom">
            <i class="iconfont icon-baojia"></i>
            <div class="menu-info">
              <div class="title">我的报价</div>
            </div>
            <i class="iconfont icon-next"></i>
          </div>
          <div @click="openMyAuth" class="menu-item border-bottom">
            <i class="iconfont icon-renzheng"></i>
            <div class="menu-info">
              <div class="title">信息认证</div>
            </div>
            <span>{{userInfo.certification | getStatus}}</span>
            <i class="iconfont icon-next"></i>
          </div>
          <div @click="openSetting" class="menu-item">
            <i class="iconfont icon-shezhi"></i>
            <div class="menu-info">
              <div class="title">设置</div>
            </div>
            <i class="iconfont icon-next"></i>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
  var app;
  apiready = function () {
    app = new Vue({
      el: '#app',
      data: {
        userInfo: {
          name: '',
          avatar: '',
          signature: '',
          occupation: '',
          background: [],
          level: '1',
          certification: '1',
        },
      },
      created: function () {
        var _this = this;
        api.setRefreshHeaderInfo({
          bgColor: '#ccc',
          textColor: '#fff',
          textDown: '下拉刷新...',
          textUp: '松开刷新...'
        }, function (ret, err) {
          _this.getUserIndex();
        });
        api.addEventListener({
          name: 'refreshMy'
        }, function (ret, err) {
          _this.getUserIndex();
        })
      },
      mounted: function () {
        var _this = this;
        _this.getUserIndex();
      },
      methods: {
        getUserIndex: function () {
          var _this = this;
          api.showProgress({
            title: '',
            text: ''
          });
          api.ajax({
            url: baseUrl + 'user/index',
            method: 'get',
            headers: {
              token: $api.getStorage('deviceToken')
            },
            data: {
              values: {
                uid: $api.getStorage('uid'),
              },
            }
          }, function (ret, err) {
            api.refreshHeaderLoadDone();
            api.hideProgress();
            if (ret.status == '200') {
              _this.userInfo = ret.data;
              $api.setStorage('uname', ret.data.name);
              $api.setStorage('uavatar', ret.data.avatar);
              $api.setStorage('usignature', ret.data.signature);
            }
          })
        },

        openEdit: function () {
          api.openWin({
            name: 'user_home',
            url: 'user_home.html',
            slidBackEnabled: false,
            pageParam: {
              member_id: $api.getStorage('uid')
            }
          });
        },

        openMyWallet: function () {
          api.openWin({
            name: 'my_wallet',
            url: 'my_wallet.html',
            bounces: false,
            pageParam: this.userInfo
          });
        },

        openMyVip: function () {
          api.openWin({
            name: 'my_vip',
            url: 'my_vip.html',
            bounces: false,
            pageParam: this.userInfo
          });
        },

        openMyShare: function () {
          api.openWin({
            name: 'my_share',
            url: 'my_share.html',
            bounces: false,
            pageParam: this.userInfo
          });
        },

        openMygift: function () {
          api.openWin({
            name: 'my_gift',
            url: 'my_gift.html',
            bounces: false,
            pageParam: this.userInfo
          });
        },

        openOffer: function () {
          var _this = this;
          if (_this.userInfo.certification == '0') {
            api.toast({
              msg: '请先进行认证',
              duration: 2000,
              location: 'bottom'
            });
            setTimeout(function () {
              api.openWin({
                name: 'my_auth',
                url: 'my_auth.html',
                bounces: false,
                pageParam: _this.userInfo
              });
            }, 1000);
          } else if (_this.userInfo.certification == '1') {
            api.openWin({
              name: 'my_price',
              url: 'my_price.html',
              bounces: false,
              pageParam: _this.userInfo
            });
          } else if (this.userInfo.certification == '2') {
            api.toast({
              msg: '认证中，请耐心等待',
              duration: 2000,
              location: 'bottom'
            });
          }
        },

        openMyAuth: function () {
          if (this.userInfo.certification == '0') {
            api.openWin({
              name: 'my_auth',
              url: 'my_auth.html',
              bounces: false,
              pageParam: this.userInfo
            });
          } else if (this.userInfo.certification == '1') {
            api.toast({
              msg: '您已认证',
              duration: 2000,
              location: 'bottom'
            });
          } else if (this.userInfo.certification == '2') {
            api.toast({
              msg: '认证中，请耐心等待',
              duration: 2000,
              location: 'bottom'
            });
          }
        },

        openSetting: function () {
          api.openWin({
            name: 'setting',
            url: 'setting.html',
            bounces: false,
            pageParam: this.userInfo
          });
        },
        openHistory: function () {
          api.openWin({
            name: 'history',
            url: 'history.html',
            bounces: false,
            pageParam: this.userInfo
          });
        }

      },
      filters: {
        getStatus: function (value) {
          if (value == '0') {
            return '未认证';
          }
          if (value == '1') {
            return '已认证';
          }
          if (value == '2') {
            return '认证中';
          }
        },
      }
    })
  }
  // 刷新页面
  function refresh() {
    api.showProgress({
      title: '',
      text: ''
    });
    setTimeout(function () {
      api.hideProgress();
      location.reload();
    }, 1000);
  }
</script>